package com.itheima.demo04.MyException;

import java.util.Scanner;

public class Demo01RegisterException extends Exception {
    static String[] usernames = {"张三", "李四", "王五"};

    public static void main(String[] args) throws RegisterException {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入您要注册的用户名:");
        String username = sc.next();
        checkUsername(username);
    }

    public static void checkUsername(String username) throws RegisterException {
        for (String name : usernames) {
            if (name.equals(username)) {
                throw new RegisterException("亲,用户名已经被注册");
            }
        }
        System.out.println("恭喜您注册成功!");
    }
}
